﻿@{
    Layout = null;
}
@using CNKI.TPI.Web.Search.Model;
@using CNKI.TPI.Web.Base;
<script>
    function addconfig() {
        var urlstr = "@Html.Raw(Url.Action("AddHomeConfig", "Admin_Home"))";
        ajaxLoad("initload", timestamp(urlstr));
    }
    function editconfig(sysid, type) {
        var urlstr = "@Html.Raw(Url.Action("UpdateHomeConfig", "Admin_Home"))";
        var dataobj = { "sysid": sysid, "type": type };//type 1 代表跳转模板
        ajaxLoad("initload", timestamp(urlstr), dataobj);
    }
    function delconfig(sysid, type) {
        var urlstr = "@Html.Raw(Url.Action("DelContentConfig", "Admin_Home"))";
        var dataobj = { "sysid": sysid, "type": type };//type 1 代表跳转模板
        confirmDialog('确定要删除吗?', function () {
            $.ajax({
                type: "GET",
                url: timestamp(urlstr),
                data: dataobj,
                success: function (msg) {
                    if (msg == "True") {
                        var urlstr = "@Html.Raw(Url.Action("Index", "Admin_Home"))";
                        ajaxLoad("initload", timestamp(urlstr)); //刷新列表页
                        messageAlert("删除成功！");

                    }
                    else {
                        messageAlert("删除失败！");
                    }
                },
                error: function (e)
                { }
            })
        })
    }
    function sortConfig() {

        if ($("#ContentCount").val() > 0) {
            //获取对应的数据
            $.ajax({
                type: "GET",
                url: timestamp("@Html.Raw(Url.Action("GetContentList", "Admin_Home"))"),
                beforeSend: function () { $("#loading").show(); },
                success: function (msg) {
                    var obj = eval(msg);
                    $(".ulfield").empty();
                    if (obj != null && obj.length > 0) {
                        for (var i = 0; i < obj.length; i++) {
                            var listr = " <li class=\"f-ct\" style=\"margin-left: 2em;\">  <label class=\"f-label block right\">" +
                           " <input type=\"checkbox\" class=\"f-checkboxR\"  value='" + obj[i].SysID + "' />" + obj[i].ColumnName + "</label></li>";
                            $(".ulfield").append(listr);
                        }
                    }
                    $("#loading").hide();
                    showConfig();
                },
                error: function (e)
                { $("#loading").hide(); }

            })


        }
        else {
            messageAlert("暂无数据，不支持排序！");
        }
      
    }
    function closeConfig() {
        $(".talkDivBg").hide();
        $(".sortConfig").hide();
    }
    function showConfig() {
        $(".talkDivBg").show();
        $(".sortConfig").show();
    }
    function saveConfig() {
        ;
        var jsondata = [];
        $('.wrapR-c-box-b-right ul input').each(function (index) {
            var dataobj = {
                "SysID": $(this).val(),
                "SortNo": index
            }
            jsondata.push(dataobj);

        })
        var dataold = { "list": jsondata };
        $.ajax({
            type: "POST",
            url: "@Html.Raw(Url.Action("UpdateHomeSort", "Admin_Home"))",
            contentType: "application/json",
            data: JSON.stringify(dataold),
            success: function (msg) {
                if (msg == "True") {
                    closeConfig();
                    ajaxLoad("initload", '@Html.Raw(Url.Action("Index", "Admin_Home"))');

                   }
                   else {
                       messageAlert("操作失败！");
                   }
               },
            error: function (e)
            { }
        })
    }
</script>
<div class="wrapR-c" style='padding-top: 20px; padding-bottom: 20px'>
        <input type="hidden" value="@ViewBag.ContentCount" id="ContentCount" />
    <div class='mb20 clearfix'>
        <a onclick="addconfig()" class="btn btn-m btn-submit btn-defa-f">添加配置</a>
        <a onclick="sortConfig()" class="btn btn-m btn-submit btn-defa-f">排序</a>
    </div>
    <table width="100%" cellspacing="0" cellpadding="0" border="0" class="table table-grey">
        <thead class='th-wr'>
            <tr class="thead">
                <th class="tdnum tdnum1">序号</th>
                <th>数据库名称</th>
                <th>数据库类型</th>
                <th>显示类型</th>
                <th>栏目名称</th>
                <th>显示状态</th>
                <th>显示位置</th>
                <th>操作</th>
            </tr>
        </thead>
        <tbody>
            @*首页模板*@
            @{if (ViewBag.ContentList != null)
              {
                  int sortno = 1;
                  string type = "";
                  foreach (SYS_CMS_NEWS_NEWSCONTENTCONFIG item in ViewBag.ContentList)
                  {
                      string str = "even";
                      if (sortno % 2 == 0)
                      {
                          str = "odd";
                      }
                      
                <tr class='@str'>
                    <td>@sortno</td>
                    <td class="tc">@item.DBName</td>
                    <td class="tc">@item.DBType</td>
                    <td class="tc">
                        @switch (item.ShowType)
                        {
                            case 1:
                                type = "图片新闻栏目";
                                break;
                            case 2:
                                type = "文章新闻栏目";
                                break;
                            case 3:
                                type = "首页推荐栏目";
                                break;
                            case 4:
                                type = "站点公告栏目";
                                break;
                            case 5:
                                type = "多媒体推荐栏目";
                                break;
                            default:
                                break;
                        }
                        @type
                    </td>
                    <td class="tc"><a style="text-decoration:none;cursor:none" title="@item.ColumnName">@ColumnAliasHelper.SubContent(item.ColumnName, 10)</a></td>
                    <td class="tc">
                        @if (@item.IsPub == 0)
                        {<i class="iconfont icon-close2 red"></i>}
                        else
                        {<i class="iconfont icon-correct3 fwb"></i>}
                    </td>


                    <td class="tc">
                        @if (@item.Location == 0)
                        {
                            @Html.Raw("左侧");
                        }
                        else
                        {
                            @Html.Raw("右侧");
                        }

                    </td>
                    <td class="tc">
                        <a href="javascript:void(0);"   onclick="javascript:editconfig('@item.SysID','0')">编辑</a>
                        <a  href="javascript:void(0);" onclick="delconfig('@item.SysID','0')">删除</a>
                    </td>
                </tr>
                        sortno = sortno + 1;
                  }
              }
            }
            @*跳转模板*@
            @{if (ViewBag.JumpList != null)
              {
                  int sortno = 1;
                  if (ViewBag.ContentList != null)
                  {
                      sortno = sortno + ViewBag.ContentList.Count;
                  }
                  foreach (SYS_CMS_NEWS_JUMPTEMPLATE item in ViewBag.JumpList)
                  {
                      string str = "even";
                      if (sortno % 2 == 0)
                      {
                          str = "odd";
                      }
                      
                <tr class='@str'>
                    <td>@sortno</td>
                    <td class="tc">@item.DBName</td>
                    <td class="tc">@item.DBType</td>
                    <td class="tc">
                        @if (item.TemplateType == 12)
                        {
                            @Html.Raw("首页跳转图片模板");
                        }
                        else
                        {
                            @Html.Raw("首页跳转文字模板");
                        }
                    </td>
                    <td class="tc"><a style="text-decoration:none;cursor:none" title="@item.ColumnName">@ColumnAliasHelper.SubContent(item.ColumnName, 10)</a></td>
                    <td class="tc">
                        @if (@item.IsPub == "0")
                        {<i class="iconfont icon-close2 red"></i>}
                        else
                        {<i class="iconfont  icon-correct3 success"></i>}
                    </td>
                    <td class="tc">
                        @if (@item.Location == 0)
                        {
                            @Html.Raw("左侧");
                        }
                        else
                        {
                            @Html.Raw("右侧");
                        }
                    </td>
                    <td class="tc">
                        <a href="javascript:void(0);"  onclick="editconfig('@item.SysID','1')">编辑</a>
                        <a  href="javascript:void(0);" onclick="delconfig('@item.SysID','1')">删除</a>
                    </td>
                </tr>
                        sortno = sortno + 1;
                  }
              }
            }


        </tbody>
    </table>

</div>


<!--透明背景-->
<div class="talkDivBg" style="display: none; z-index: 999">
    <div class="talkDiv talkDivTr talkW-550 form-h sortConfig" style='margin-top: -278px; display: none'>
        <div class="talkDiv-title">
            <span>首页栏目排序</span>
            <a class="icon icon-close" title="关闭" href="javascript:void(0);" onclick="closeConfig()"><i class="iconfont icon-error3"></i></a>
        </div>
        <div class="talkDiv-body talkDiv-body1">

            <div class="f-gp" style="padding-left: 70px">

                <div class='wrapR-c-box wrapR-c-r wrapR-c-r-l' style="overflow-y: visible; height: 430px">
                    <div class="wrapR-c-box-t">首页栏目列表</div>
                    <div class="wrapR-c-box-b-right" style="overflow-y: scroll; height: 390px">
                        <ul class="ulfield">
                            @*  @if (ViewBag.ContentList != null)
                                {
                                    foreach (SYS_CMS_NEWS_NEWSCONTENTCONFIG item in ViewBag.ContentList)
                                    {

                                    <li class="f-ct" style="margin-left: 2em;">
                                        <label class="f-label block right">
                                            <input type="checkbox" class="f-checkboxR" value='@item.SysID' />@item.ColumnName</label>

                                    </li>
                                    }
                                }*@
                        </ul>
                    </div>
                </div>

                <div class="wrapR-c-r-r form-h posa" style="top: 80px; left: 400px;">
                    <div>
                        <a title="移至最顶部" onclick=" movefirst(this)" class="iconfont-s iconfont-upest-s"></a>
                        <br />
                        <a title="上移" onclick="moveablove(this)" class="iconfont-s iconfont-up-s"></a>
                        <br />
                        <a title="下移" onclick="movedown(this)" class="iconfont-s iconfont-down-s"></a>
                        <br />
                        <a title="移至最底部" onclick="movelast(this)" class="iconfont-s iconfont-downest-s"></a>
                    </div>
                </div>
            </div>
            <div class="f-gp">
                <div class="f-lb">
                    <label class="f-label"></label>
                </div>
                <div class="f-ct" style="margin-left: 150px">
                    <a href="javascript:void(0);" class="btn btn-m btn-prim-f btn-submit" onclick="saveConfig()">保存</a>
                </div>
            </div>
        </div>
    </div>
</div>